#include "../wxsitemresdata.h"
#include "wxsfindreplacedialog.h"
#include <wx/fdrepdlg.h>

namespace {
  wxsRegisterItem<wxsFindReplaceDialog> Reg( _T( "FindReplaceDialog" ), _T( "查找位置对话框" ), wxsTTool, _T( "对话框" ), 170, false );
  WXS_ST_BEGIN( wxsFindReplaceDialogStyles, NULL );
  WXS_ST_CATEGORY( "wxFindReplaceDialog" )
  WXS_ST( wxFR_REPLACEDIALOG )
  WXS_ST( wxFR_NOUPDOWN )
  WXS_ST( wxFR_NOMATCHCASE )
  WXS_ST( wxFR_NOWHOLEWORD )
  WXS_ST_END()
  WXS_EV_BEGIN( wxsFindReplaceDialogEvents )
  WXS_EVI( EVT_FIND, wxEVT_COMMAND_FIND, wxFindDialogEvent, Find )
  WXS_EVI( EVT_FIND_NEXT, wxEVT_COMMAND_FIND_NEXT, wxFindDialogEvent, FindNext )
  WXS_EVI( EVT_FIND_REPLACE, wxEVT_COMMAND_FIND_REPLACE, wxFindDialogEvent, Replace )
  WXS_EVI( EVT_FIND_REPLACE_ALL, wxEVT_COMMAND_FIND_REPLACE_ALL, wxFindDialogEvent, ReplaceAll )
  WXS_EVI( EVT_FIND_CLOSE, wxEVT_COMMAND_FIND_CLOSE, wxFindDialogEvent, Close )
  WXS_EV_END()
}

wxsFindReplaceDialog::wxsFindReplaceDialog( wxsItemResData *Data ):
  wxsTool( Data, &Reg.Info, wxsFindReplaceDialogEvents, wxsFindReplaceDialogStyles,
           ( flVariable | flId | flSubclass | flExtraCode ) ),
  m_sCaption( wxEmptyString ) {
}

void wxsFindReplaceDialog::OnBuildCreatingCode() {
  wxString sfindReplaceData;
  wxString sNote( _T( "// NOTE: 为了使事件正确连接，必须设置此 wxFindReplaceDialog to -1 in wxSmith." ) );
  switch( GetLanguage() ) {
    case wxsCPP:
      AddHeader( _T( "<wx/fdrepdlg.h>" ), GetInfo().ClassName, 0 );
      sfindReplaceData = GetCoderContext()->GetUniqueName( _T( "findReplaceData" ) );
      AddDeclaration( wxString::Format( wxT( "wxFindReplaceData %s;" ), sfindReplaceData.wx_str() ) );
      Codef( _T( "\t%s\n" ), sNote.wx_str() );
      Codef( _T( "%C(%W, &%s, %t, %T);\n" ), sfindReplaceData.wx_str(), m_sCaption.wx_str() );
      BuildSetupWindowCode();
      break;
    case wxsUnknownLanguage:
    default:
      wxsCodeMarks::Unknown( _T( "wxsFindReplaceDialog::OnBuildCreatingCode" ), GetLanguage() );
  }
}

void wxsFindReplaceDialog::OnEnumToolProperties( M_Code_unused long Flags ) {
  WXS_SHORT_STRING( wxsFindReplaceDialog, m_sCaption, _T( "Caption" ), _T( "caption" ), wxEmptyString, false );
}
